﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>

    <link href="~/Content/jquery-easyui-1.5.2/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.5.2/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/EasyUI/jquery.min.js"></script>
    <script src="~/Content/jquery-easyui-1.5.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.5.2/locale/easyui-lang-zh_CN.js"></script>
    @*<link href="~/Content/jquery-easyui-1.5.2/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/jquery-easyui-1.5.2/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/jquery-easyui-1.5.2/jquery.easyui.min.js"></script>*@

    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ui7X2CSu3ITjojARL4tILi5W1i9gkDVS"></script>
</head>
<body>

    <div data-options="region:'center',title:'Center'">
        <div class="easyui-panel" title="New Topic" style="width:100%;padding:30px 60px;">
            <form id="ff" method="post">

                <div style="margin-bottom:20px">
                    <input type="hidden" id="dp" value="@ViewBag.id" />
                    <input class="easyui-textbox" id="Name" style="width:100%" data-options="label:'所在楼号:',required:true">
                </div>
                <div style="width:100%;height:400px">
                    <div style="float:left;width:5%;margin-top:350px"><a class="easyui-linkbutton" id="sure">确定坐标</a></div>
                    <div id="map" style="width:95%;height:400px;float:left"></div>
                </div>
                <div style="margin-bottom:20px">
                    <input class="easyui-textbox" id="subject" style="width:100%" data-options="label:'定位坐标:',required:true">
                </div>
                <div style="margin-bottom:20px">
                    <input class="easyui-textbox" id="location" style="width:100%" data-options="label:'地处位置:'">
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="jiegou" label="房屋结构" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="type" label="建筑类型" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="outs" label="外墙面装饰" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="publics" label="公共部位装饰" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="dt" label="电梯" style="width:100%"></select>
                    <input class="easyui-numberbox" id="number" label="数量" min="1" max="8" precision="0" />
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="qi" label="供气" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="water" label="供水" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="nuan" label="供暖" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-combobox" id="door" label="门禁系统" style="width:100%"></select>
                </div>
                <div style="margin-bottom:20px">
                    <select class="easyui-textbox" id="others" label="其他" style="width:100%" multiline="true"></select>
                </div>
            </form>
            <div style="text-align:center;padding:5px 0">
                <a id="ins" href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm(1)" style="width:80px">保存</a>
                <a id="upd" href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm(2)" style="width:80px">修改</a>
            </div>
        </div>
    </div>

</body>
</html>
<script type="text/javascript">
    $("#upd").hide();
    var urls = "http://localhost:63805/";
    var Urls = window.location.href;
    var Sums = Urls.split("=");
    var projectNumber = Sums[1];
    publics(projectNumber);
    function submitForm(id) {
        if (id == 1) {
            //alert($("#dp").val());
            //alert($("#type").combobox("getValue"));
            $.ajax({
                url: "http://localhost:63805/apis/Floors/insert",
                data: { floor_Explain: $("#others").textbox("getValue"), floor_Door: $("#door").combobox("getValue"), floor_Warm: $("#nuan").combobox("getValue"), floor_Water: $("#water").combobox("getValue"), floor_Gas: $("#qi").combobox("getValue"), floor_LiftNum: $("#number").textbox("getValue"), floor_Lift: $("#dt").combobox("getValue"), floor_Public: $("#publics").combobox("getValue"), floor_Facade: $("#outs").combobox("getValue"), floor_BuildType: $("#type").combobox("getValue"), projectNumber: $("#dp").val(), floor_Number: $("#Name").textbox("getValue"), floor_Landmark: $("#subject").textbox("getValue"), floor_Address: $("#location").textbox("getValue"), floor_HouseStructure: $("#jiegou").combobox("getValue") },
                dataType: "json",
                type: "post",
                success: function (obj) {
                    if (obj > 0) {
                        alert("修改成功!");
                        location.href = '/prospect/prospects/' + localStorage.getItem("id");
                    }
                    else {
                        alert("失败!");
                    }

                }
            })
        }
        else {
            $.ajax({
                url: "http://localhost:63805/api/Floors/" + projectNumber,
                data: { floor_Explain: $("#others").textbox("getValue"), floor_Door: $("#door").combobox("getValue"), floor_Warm: $("#nuan").combobox("getValue"), floor_Water: $("#water").combobox("getValue"), floor_Gas: $("#qi").combobox("getValue"), floor_LiftNum: $("#number").textbox("getValue"), floor_Lift: $("#dt").combobox("getValue"), floor_Public: $("#publics").combobox("getValue"), floor_Facade: $("#outs").combobox("getValue"), floor_BuildType: $("#type").combobox("getValue"), projectNumber: $("#dp").val(), floor_Number: $("#Name").textbox("getValue"), floor_Landmark: $("#subject").textbox("getValue"), floor_Address: $("#location").textbox("getValue"), floor_HouseStructure: $("#jiegou").combobox("getValue") },
                dataType: "json",
                type: "put",
                success: function (obj) {
                    if (obj > 0) {
                        alert("修改成功!");
                        location.href = '/prospect/prospects/' + localStorage.getItem("id");
                    }
                    else {
                        alert("失败!");
                    }

                }
            })
        }
    }
    
    function publics(id) {

        $.ajax({
            url: urls + "apis/Floors/getmodel/" + id,
            dataType: "json",
            type: "get",
            success: function (obj) {
                
                if (obj != null) {
                    $("#upd").show();
                    $("#ins").hide();
                    $("#Name").textbox("setValue", obj.floor_Number);
                    $("#subject").textbox("setValue", obj.floor_Landmark);
                    var loca = (obj.floor_Landmark).split(',');
                   // alert(loca[1]);
                    var map = new BMap.Map("map");                     // 创建Map实例
                    var point = new BMap.Point(loca[0], loca[1]);    // 创建点坐标
                    var gc = new BMap.Geocoder();
                    map.centerAndZoom(point, 10);                      // 初始化地图,设置中心点坐标和地图级别。
                    map.enableScrollWheelZoom();                       //解锁滑轮

                    $("#location").textbox("setValue", obj.floor_Address);

                    $("#number").textbox("setValue", obj.floor_LiftNum);

                    $("#jiegou").combobox({
                        url: "/single/structs",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#jiegou").combobox("setValue", obj.floor_HouseStructure);
                        }
                    })
                    $("#type").combobox({
                        url: "/single/types",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#type").combobox("setValue", obj.floor_BuildType);
                        }
                    })
                    $("#outs").combobox({
                        url: "/single/outs",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#outs").combobox("setValue", obj.floor_Facade);
                        }
                    })
                    $("#publics").combobox({
                        url: "/single/publics",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#publics").combobox("setValue", obj.floor_Public);
                        }
                    })
                    $("#dt").combobox({
                        url: "/single/dian",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#dt").combobox("setValue", obj.floor_Lift);
                        }
                    })

                    $("#qi").combobox({
                        url: "/single/gong",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#qi").combobox("setValue", obj.floor_Gas);
                        }
                    })

                    $("#water").combobox({
                        url: "/single/water",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#water").combobox("setValue", obj.floor_Water);
                        }
                    })

                    $("#nuan").combobox({
                        url: "/single/nuan",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#nuan").combobox("setValue", obj.floor_Warm);
                        }
                    })

                    $("#door").combobox({
                        url: "/single/door",
                        valueField: "value",
                        textField: "text",
                        onLoadSuccess: function () {
                            $("#door").combobox("setValue", obj.floor_Door);
                        }
                    })

                    $("#others").textbox("setValue", obj.floor_Explain);


                }
                else
                {
                    var map = new BMap.Map("map");            // 创建Map实例
                    var point = new BMap.Point(116.404, 39.915);    // 创建点坐标
                    var gc = new BMap.Geocoder();
                    map.centerAndZoom(point, 6);                     // 初始化地图,设置中心点坐标和地图级别。
                    map.enableScrollWheelZoom();
                    map.addEventListener("click", diji);
                    function diji(e) {//添加一个单击事件
                        $("#subject").textbox("setValue", e.point.lng + "," + e.point.lat);
                        var pp = e.point;//拿到坐标点
                        gc.getLocation(pp, function (rs) {//用获取地址的方法传入坐标点生成坐标地址
                            var addComp = rs.addressComponents;
                            $("#location").textbox("setValue", addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
                        });
                    }
                    $("#sure").bind("click", function () {
                        $("#subject").textbox("disable", true);
                        $("#location").textbox("disable", true);
                        map.removeEventListener("click", diji);
                        $.ajax({
                            url: "http://localhost:63805/apis/Basic_Info/putsate/" + $("#dp").val(),
                            dataType: "json",
                            type: "put",
                            success: function (obj) {

                            }
                        })
                    });
                    $("#type").combobox({
                        url: "/Floors/types",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#jiegou").combobox({
                        url: "/Floors/structs",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#outs").combobox({
                        url: "/Floors/outs",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#publics").combobox({
                        url: "/Floors/publics",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#dt").combobox({
                        url: "/Floors/dian",
                        valueField: "value",
                        textField: "text",
                        onChange: function (n, o) {
                            if ($("#dt").combobox("getText") == "无电梯") {
                                $("#number").numberbox("disable", true);
                            }
                        }
                    })
                    //$("#publics").combobox({
                    //    url: "/Floors/publics",
                    //    valueField: "value",
                    //    textField: "text"
                    //})
                    $("#qi").combobox({
                        url: "/Floors/gong",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#water").combobox({
                        url: "/Floors/water",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#nuan").combobox({
                        url: "/Floors/nuan",
                        valueField: "value",
                        textField: "text"
                    })
                    $("#door").combobox({
                        url: "/Floors/door",
                        valueField: "value",
                        textField: "text"
                    })
                }
            }
        })
    }//楼状
</script>
